package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
)

func writeDemo1() {
	fileobj, err := os.OpenFile("./xxx.txt", os.O_APPEND|os.O_CREATE, 0644)
	if err != nil {
		fmt.Printf("错误信息：%v", err)
		return
	}
	fileobj.Write([]byte("asda asasdad\n"))
	fileobj.WriteString("是的冯绍峰")
	fileobj.Close()
}
func writeDemo2() {
	fileobj, err := os.OpenFile("./xxx.txt", os.O_APPEND|os.O_CREATE, 0644)
	if err != nil {
		fmt.Printf("错误信息：%v", err)
		return
	}
	defer fileobj.Close() //关闭文件

	ws := bufio.NewWriter(fileobj)
	ws.WriteString("hello wujiangpan \n")
	ws.Flush()
}
func writeDemo3() {
	str := "hello 沙河1"
	err := ioutil.WriteFile("./xx.txt", []byte(str), 0666)
	if err != nil {
		fmt.Println("write file failed, err:", err)
		return
	}
}

func main() {
	// writeDemo1()
	writeDemo2()
	writeDemo3()

}
